package com.example.springcloud.alibaba.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.example.springcloud.alibaba.myhandler.CustomerBlockHandler;
import com.example.springcloud.entities.CommonResult;
import com.example.springcloud.entities.Payment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class FlowLimitController {
    @GetMapping("/testA")
    public String testA() {
        return "---------testA";
    }

    @GetMapping("/testB")
    public String testB() {
        return "---------testB";
    }
    @GetMapping("/rateLimit/customerBlockHandler/{id}")
    @SentinelResource(value = "customerBlockHandler",
            blockHandlerClass = CustomerBlockHandler.class,
            fallbackClass = CustomerBlockHandler.class,
            fallback = "handlerException3",
            blockHandler = "handlerException2")
    public CommonResult customerBlockHandler(@PathVariable Long id) {
        if(id == 4) {
            throw new RuntimeException("非法参数异常...");
        }
        return new CommonResult(200,"按客户自定义",new Payment(2020L,"serial003"));
    }
}
